package cn.gxa.j229.bug.finance.controller.loanuser;



import cn.gxa.j229.bug.finance.BusinessException;
import cn.gxa.j229.bug.finance.pojo.InvestmentUser;
import cn.gxa.j229.bug.finance.service.loanuser.InvestmentUserService;
import cn.gxa.j229.bug.finance.utils.JsonResult;
import cn.gxa.j229.bug.finance.utils.MD5Util;
import cn.gxa.j229.bug.finance.utils.PageUtils;
import cn.gxa.j229.bug.finance.utils.Salt;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.swing.plaf.basic.BasicButtonUI;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/invest")
public class InvestmentUserController {
    @Resource
    InvestmentUserService investmentUserService = null;



    @PostMapping("/bypage")
    @ResponseBody
    public Map findByPage(@RequestBody InvestmentUser investmentUser){
        JsonResult jsonResult = new JsonResult();
        List<Map<String, String>> allByPage = investmentUserService.findAllByPage(investmentUser);
        int counts = investmentUserService.countByPage();
        if (allByPage!=null){
            jsonResult.setData(allByPage);
            jsonResult.put("counts",counts);
            jsonResult.setCode("200");
            jsonResult.setMsg("操作成功");
            return jsonResult.getValues();
        }
        throw new BusinessException("500","查询失败");
    }


    @PostMapping("/byname")
    @ResponseBody
    public Map findByName(@RequestBody InvestmentUser investmentUser){
        JsonResult jsonResult = new JsonResult();
        List<Map<String, String>> byName = investmentUserService.findByName(investmentUser);
        int counts = investmentUserService.countByName(investmentUser);
        if (byName!=null){
            jsonResult.setData(byName);
            jsonResult.put("counts",counts);
            jsonResult.setCode("200");
            jsonResult.setMsg("操作成功");
            return jsonResult.getValues();
        }
        throw new BusinessException("500","查询失败");

    }

    @PostMapping("/updatesock")
    @ResponseBody
    public Map updateSock(@RequestBody InvestmentUser investmentUser){
        JsonResult jsonResult = new JsonResult();
        int b = investmentUserService.updateByPrimaryKeySelective(investmentUser);
        if (b==1){
            jsonResult.setCode("200");
            jsonResult.setMsg("修改成功");
            return jsonResult.getValues();
        }
        throw new BusinessException("500","修改失败");
    }


    @PostMapping("/updatepsd")
    @ResponseBody
    public Map updatePassword(@RequestBody InvestmentUser investmentUser){
        JsonResult jsonResult = new JsonResult();
        int i = investmentUserService.updateByPrimaryKeySelective(investmentUser);
        if (i==1){
            jsonResult.setCode("200");
            jsonResult.setMsg("修改成功");
            return jsonResult.getValues();
        }
        throw new BusinessException("500","修改失败");

    }


    @PostMapping("/byid")
    @ResponseBody
    public Map findById(@RequestBody InvestmentUser investmentUser){
        JsonResult jsonResult = new JsonResult();
        List<Map<String, String>> maps = investmentUserService.selectByPrimaryKey(investmentUser.getId());
        if (maps!=null){
            jsonResult.setCode("200");
            jsonResult.setMsg("查询成功");
            jsonResult.setData(maps);
            return jsonResult.getValues();
        }
        throw new BusinessException("500","查询失败");
    }

    @PostMapping("/insert")
    @ResponseBody
    public Map insert(@RequestBody InvestmentUser investmentUser){
        JsonResult jsonResult = new JsonResult();
        int i = investmentUserService.updateByPrimaryKeySelective(investmentUser);
        if (i==1){
            jsonResult.setCode("200");
            jsonResult.setMsg("添加成功");
            return jsonResult.getValues();
        }
        throw new BusinessException("500","添加失败");
    }

}
